package com.xm.servlet.reception_desk.address;


import com.xm.entity.Address;
import com.xm.service.reception_desk.AddressService;
import lombok.SneakyThrows;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author 田顺琪
 * @date 2024-01-10
 */
@WebServlet(name = "AddressServlet", value = "/address")
public class AddressServlet extends HttpServlet {
    private final AddressService service=new AddressService();
    @SneakyThrows
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int addressId=Integer.parseInt(req.getParameter("addressId"));
        String name = req.getParameter("name");
        String phone = req.getParameter("phone");
        String provinceCityRegion = req.getParameter("address");
        String[] assembly = provinceCityRegion.split(" ");
        String fullAddress = req.getParameter("fullAddress");
        String label = req.getParameter("label");
        int informationId = Integer.parseInt(req.getParameter("informationId"));
        System.out.println(informationId);
        String lng = req.getParameter("lng");
        String lat = req.getParameter("lat");
        Address address = new Address(addressId,name,phone,assembly[0],assembly[1],assembly[2],fullAddress,label,informationId,lng,lat);
        boolean whether = service.saveOrUpdateAddress(address);
    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int addressId=Integer.parseInt(req.getParameter("addressId"));
        boolean whether = service.getAddressDelete(addressId);
    }
}
